package cn.mymall.entity.mall;

import cn.mymall.constant.MallConstant;
import cn.mymall.util.DateUtil;
import cn.mymall.util.RandomUtil;
import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.math.BigDecimal;
import java.sql.Timestamp;

/**
 * <p>
 *
 * </p>
 *
 * @author liqilun
 * @since 2021-07-23
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName("mall_product")
public class Product extends Model {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    private String attrName;

    private Integer categoryId;

    private String introduction;

    private String logo;

    private String name;

    private String flag;

    private Timestamp offSaleTime;

    private Timestamp onSaleTime;

    private Integer shipperId;

    private Integer shippingTemplateId;

    private Integer sold;

    private Integer sortNo;

    private String status;

    private Integer vendorId;

    private Integer version;

    private BigDecimal price;

    private Integer sold2;

    private Integer subCategoryId;

    private String citycodes;

    private String otherInfo;

    private Timestamp addTime;

    //配送省份模式: 包含、排除
    private String deliveryProvinceMode;
    //配送省份编码
    private String deliveryProvincecodes;

    private String tingsType;

    private Integer elecBatchId;
    //多少小时内最多购买和maxCnt并用
    private Integer withinHour;
    //最多购买数量
    private Integer maxCnt;
    //展示给用户的备注（礼包的订单，分多个快递单，要告知用户）
    private String showMemberRemark;

    /**
     * 渠道商商品ID
     */
    private String partnerGoodsId;

    /**
     * 渠道商编码
     */
    private String partnerCode;

    private String relateProductIds;

    public Product(){
        this.sold = 0;
        this.sold2 = RandomUtil.randomInt(2);
        this.version = 0;
        this.addTime = DateUtil.getCurFullTimestamp();
        this.status = MallConstant.PRODUCT_STATUS_OFF_SALE;
        this.otherInfo = "{}";
        this.sortNo=99999;
    }
    public boolean hasBooking(){
        Timestamp curtime = DateUtil.getCurFullTimestamp();
        return StringUtils.equals(status, MallConstant.PRODUCT_STATUS_ON_SALE)
                && onSaleTime.before(curtime) && offSaleTime.after(curtime);
    }
    public boolean isCate(){
        return categoryId.equals(MallConstant.CATEGORY_CAKE_ID);
    }
    public boolean isBook(){
        return categoryId.equals(MallConstant.CATEGORY_BOOK_ID);
    }
    public boolean hasElecProduct(){
        return StringUtils.equalsIgnoreCase(MallConstant.TINGS_TYPE_ELEC, tingsType);
    }

    public boolean hasElecManualProduct(){
        return StringUtils.equalsIgnoreCase(MallConstant.TINGS_TYPE_ELEC_MANUAL, tingsType);
    }


    public boolean hasDaigou(){
        return StringUtils.equalsIgnoreCase(MallConstant.TINGS_TYPE_DAIGOU, tingsType);
    }
}
